import json

from common.consumer import ConsumerBase
from common.im_util import im_client
from common.log import Log


class IMClientConsumer(ConsumerBase):
    """
    create by ld_wu 2018-01-25
    中标的用户消费者
    """

    @staticmethod
    def msg_callback(channel, method, properties, body):
        params = json.loads(body)
        Log.info(body)
        try:
            res = getattr(im_client, params['func'])(
                *params['args'],
                **params['kwargs']
            )
            Log.info(res)
        except Exception as e:
            Log.info('IMClientConsumer failed: {}'.format(e))